#ifndef	_SYS_UTIL_H_
#define	_SYS_UTIL_H_
#include <common.h>

int tcp_client(uint16_t port);
//总的初始化函数
int tcp_server_sock_init(const char *host,uint16_t port);

//获取本地ip
int getlocalip(char *ip);

void activate_nonblock(int fd);

void deactivate_nonblock(int fd);

/**
 * read_timeout
 * 输入参数sock_fd套接字timeval超时时间（秒）
 * 如果超时时间为0则不进行超时
 * 返回-1且errno为ETIMEDOUT为超时否则返回0
 **/
int read_timeout(int sockfd,int timeval);
/**
 * write_timeout
 **/
int write_timeout(int sockfd,int timeval);
/**
 * accept_timeout
 **/
int accept_timeout(int sockfd,struct sockaddr *addr,
		socklen_t *addrlen,int timeval);
/**
 * connect_timeout
 **/
int connect_timeout(int sockfd,const struct sockaddr *addr,
			socklen_t addrlen,int timeval);

ssize_t readn(int fp,void *buf,size_t count);

ssize_t writen(int fp,const void *buf,size_t count);

ssize_t recv_peek(int sockfd,void *buf,size_t len);

ssize_t readline(int sockfd,void *buf,size_t maxline);

int send_fd(int sock_fd,int fd);

int recv_fd(const int sock_fd);

//加读锁
int lock_file_read(int fd);

int lock_file_write(int fd);

int unlock_file(int fd);

long get_time_sec(void);

long get_time_usec(void);

void nano_sleep(double seconds);

void activate_oobinline(int fd);

void activate_sigurg(int fd);

#endif

